package org.example.testdemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.testdemo.pojo.PageReq;
import org.example.testdemo.pojo.User;
import org.example.testdemo.pojo.combination.UserInformation;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("<script> " +
            "SELECT a.name,a.userId,b.permissionName,c.b_Name,c.b_Code  " +
            "FROM user AS a,permission AS b,department AS c  " +
            "WHERE a.permissionId=b.permissionId AND a.b_Code=c.b_Code " +
            "<if test='name != null'>" +
            "and a.name LIKE CONCAT('%', #{name}, '%') " +
            "</if>" +
            "<if test='department != null'>" +
            "and a.b_Code = #{department}" +
            "</if>" +
            "</script>")
    public IPage<UserInformation> getUser(@Param("name")String name,@Param("department")String department,IPage<?> page);


    @Select("<script>" +
            "SELECT * FROM `user` " +
            "WHERE `userId` NOT IN((SELECT b.`userId` FROM `authorize` AS a,`user` AS b WHERE a.`userId`=b.`userId` AND a.`p_id`=#{projectId}))" +
            " and b_Code = #{department} " +
            "<if test='name != null'>" +
            "and name LIKE CONCAT('%', #{name}, '%') " +
            "</if>" +
            "</script>")
    public IPage<UserInformation> getUserExclude(String name, String department,String projectId, Page<UserInformation> pageReq);

}
